/**
 * 
 */
package com.dsteiner.xelavos.client;


import com.dsteiner.widgets.client.JsUtil;
import com.dsteiner.widgets.client.PrefilledRichTextArea;
import com.dsteiner.widgets.client.PrefilledTextArea;
import com.dsteiner.widgets.client.PrefilledTextBox;
import com.dsteiner.widgets.client.SuggestBoxWidget;
import com.dsteiner.widgets.client.Widgets.FlowPanelExt;
import com.dsteiner.widgets.client.Widgets.LazyWidget;
import com.dsteiner.widgets.client.model.PrefilledTextBoxModel;
import com.dsteiner.widgets.client.model.SuggestBoxModel;
import com.dsteiner.xelavos.client.constants.Constants;
import com.dsteiner.xelavos.client.controller.CreateServiceController;
import com.dsteiner.xelavos.client.model.CreateObjectModel;
import com.dsteiner.xelavos.client.model.MainTabModel;
import com.google.gwt.user.client.ui.Widget;

public class CreateServiceWidget extends LazyWidget {

	private final CreateServiceController createServiceController;
	private final CreateObjectModel createObjectModel;
	private final MainTabModel mainTabModel;

	public CreateServiceWidget(CreateServiceController createServiceController, 
			CreateObjectModel createObjectModel, MainTabModel mainTabModel) {
		this.createServiceController = createServiceController;
		this.createObjectModel = createObjectModel;
		this.mainTabModel = mainTabModel;
	}
	
	@Override
	public Widget createContentWidget() {
		FlowPanelExt flowPanel = new FlowPanelExt();
		PrefilledTextBoxModel nameTextBoxModel = new PrefilledTextBoxModel();
		nameTextBoxModel.setDefaultText("<span class=\"main\">nombre</span> (ej Carlos Lopez)");
		PrefilledTextBox nameTextBox = new PrefilledTextBox(nameTextBoxModel);
		SuggestBoxModel typeTextBoxModel = new SuggestBoxModel();
		SuggestBoxWidget typeTextBox = new SuggestBoxWidget(typeTextBoxModel, new SelectedTabSuggestBoxDataProvider(mainTabModel));
		typeTextBoxModel.setDefaultText("<span class=\"main\">tipo de servicio</span> <span class=\"requiredField\">*</span> (ej Arquitecto)");
		PrefilledTextBoxModel placeTextBoxModel = new PrefilledTextBoxModel();
		placeTextBoxModel.setDefaultText("<span class=\"main\">lugar</span> (ej 14 Av 2-34 Zona 1 Xela)");
		PrefilledTextBox placeTextBox = new PrefilledTextBox(placeTextBoxModel);
		PrefilledTextBoxModel descriptionTextBoxModel = new PrefilledTextBoxModel();
		descriptionTextBoxModel.setDefaultText("<span class=\"main\">descripcion</span> <span class=\"requiredField\">*</span> (ej " +
				"especialista en crimenes y derechos humanos)");
		PrefilledRichTextArea descriptionTextBox = new PrefilledRichTextArea(descriptionTextBoxModel);
		PrefilledTextBoxModel contactTextBoxModel = new PrefilledTextBoxModel();
		contactTextBoxModel.setDefaultText("<span class=\"main\">contacto</span> <span class=\"requiredField\">*</span> (ej email y/o telefono)");
		PrefilledTextArea contactTextBox = new PrefilledTextArea(contactTextBoxModel);
		
		contactTextBoxModel.setMaxCount(Constants.MAX_COUNT_STRING);
		
		flowPanel.add((Widget)typeTextBox);
		flowPanel.add((Widget)nameTextBox);
		flowPanel.add((Widget)placeTextBox);
		flowPanel.add((Widget)contactTextBox);
		flowPanel.add((Widget)descriptionTextBox);
		
		typeTextBox.setTabIndex(94);
		nameTextBox.setTabIndex(95);
		placeTextBox.setTabIndex(96);
		contactTextBox.setTabIndex(97);
		descriptionTextBox.setTabIndex(98);

		typeTextBox.getElement().getStyle().setZIndex(10);
		nameTextBox.getElement().getStyle().setZIndex(9);
		placeTextBox.getElement().getStyle().setZIndex(8);
		contactTextBox.getElement().getStyle().setZIndex(7);
		descriptionTextBox.getElement().getStyle().setZIndex(6);
		
		createServiceController.registerPlaceTextBoxModel(placeTextBoxModel);
		createServiceController.registerTypeTextBoxModel(typeTextBoxModel);
		createServiceController.registerNameTextBoxModel(nameTextBoxModel);
		createServiceController.registerDescriptionTextBoxModel(descriptionTextBoxModel);
		createServiceController.registerContactTextBoxModel(contactTextBoxModel);
		createServiceController.registerCreateObjectWidget(this);
		createServiceController.registerCreateObjectModel(createObjectModel);
		createServiceController.registerJsUtil(JsUtil.getInstance());
		
		return flowPanel;
	}
}